<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .box {
        width: 1000px;
        height: 475px;
        margin: 0 auto;
        margin-top: 100px;
    }

    .tab {
        border: 1px solid #ddd;
        border-bottom: 0;
        height: 35px;
        width: 320px;
    }

    .tab li {
        position: relative;
        float: left;
        width: 80px;
        height: 34px;
        line-height: 34px;
        text-align: center;
        cursor: pointer;
        border-top: 4px solid #fff;
    }

    .tab span {
        position: absolute;
        right: 0;
        top: 10px;
        background-color: #ddd;
        width: 1px;
        height: 14px;
        overflow: hidden;
    }

    .products {
        width: 1002px;
        border: 1px solid #ddd;
        height: 476px;
    }

    /* 如果有两个class类中间.tab_item.active'中间不要有空格 */
    .products .main.active {
        display: block;
    }

    /* 如果有两个class类中间.tab_item.active'中间不要有空格 */
    .tab li.active {
        border-color: red;
        border-bottom: 0;
    }

    .main {
        display: none;
    }
</style>

<body>
    <div class="box">
        <ul class="tab">
            <li class="tab_item active">国际大牌<span>◆</span></li>
            <li class="tab_item">国妆名牌<span>◆</span></li>
            <li class="tab_item">清洁用品<span>◆</span></li>
            <li class="tab_item">男士精品<span>◆</span></li>
        </ul>
        <div class="products">
            <div class="main active">内容1</div>
            <div class="main">内容2</div>
            <div class="main">内容3</div>
            <div class="main">内容4</div>
        </div>
    </div>
    <script>
        // 获取元素
        // 得到所有的小li
        let lis = document.querySelectorAll('.tab .tab_item')
        let divs = document.querySelectorAll('.products .main')
        // console.log(lis);
        // 1.头部tab栏切换模块
        // 1.1先给4个小li添加点击事件
        for (let i = 0; i < lis.length; i++) {
            lis[i].addEventListener('click', function () {
                // console.log(11);
                // 找到以前的active类，移除掉(如果有两个class类中间.tab_item.active'中间不要有空格)
                // document.querySelector('.tab .tab_item.active').classList.remove('active')
                document.querySelector('.tab .active').classList.remove('active')
                this.classList.add('active')

                // 2.底部显示隐藏模块
                document.querySelector('.products .active').classList.remove('active')
                // div对应序号的那个加上active
                divs[i].classList.add('active')
            })

        }
    </script>
</body>

</html>